import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import os
import sys
from ddt import ddt, file_data
# 怎么把public/common中的方法导入进来
pathmf=os.path.abspath(os.path.dirname(os.path.dirname(__file__)))+"\\dataa\\dataqiantainichengfalse.json"
pamf=os.path.abspath(os.path.dirname(os.path.dirname(__file__)))+"\\dataa\\w.jpg"
# 将其追加到sys.path
sys.path.append(pathmf)
from mfxt.publick.common import denlu,tuichu,quitbrower

# 创建单元测试类
@ddt
class mifeng_reg_username(unittest.TestCase):
    def setUp(self):
        # 创建浏览器对象
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.driver.get("http://39.101.167.251/qftest/")
        denlu(self.driver)
    @file_data(pathmf)
    def test_mifeng_geren_updata(self,n,q,ge,expect):
        self.driver.find_element(By.LINK_TEXT, '个人资料').click()
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="avatar-form"]/input[1]').send_keys(pamf)
        self.driver.find_element(By.XPATH, '//*[@id="save-avatar-btn"]').click()
        time.sleep(2)
        self.driver.find_element(By.ID, "nickname").clear()
        self.driver.find_element(By.ID, "nickname").send_keys(n)
        self.driver.find_element(By.ID, 'qq').clear()
        self.driver.find_element(By.ID, 'qq').send_keys(q)
        self.driver.find_element(By.NAME, 'gender').click()
        self.driver.find_element(By.XPATH, '//*[@id="birth_year"]/option[78]').click()
        self.driver.find_element(By.XPATH, '//*[@id="birth_month"]/option[12]').click()
        self.driver.find_element(By.XPATH, '//*[@id="birth_day"]/option[13]').click()
        self.driver.find_element(By.ID, "signature").clear()
        self.driver.find_element(By.ID, "signature").send_keys(ge)
        self.driver.find_element(By.XPATH, '//*[@id="profile-form"]/div/button').click()

        # 断言
        expect_value = expect
        actual_value = self.driver.find_element(By.XPATH, '//*[@id="profile-form"]/dl[1]/dd/span/font').text
        self.assertEqual(expect_value, actual_value, "预期和实际结果不一致！！")

        def tearDown(self):
            # 退出登录和关闭浏览器
            tuichu(self.driver)


if __name__ == '__main__':
    unittest.main()